package com.anan.service.imp;

import com.anan.entity.po.UserFileInfo;
import com.anan.entity.query.UserFileInfoQuery;
import com.anan.mapper.UserFileInfoMapper;
import com.anan.service.UserFileInfoService;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserFileInfoServiceImp implements UserFileInfoService {

    @Resource
    UserFileInfoMapper userFileInfoMapper;


    @Override
    public UserFileInfo insertb(UserFileInfo query) {
        String random;
        while (true){
            random = RandomStringUtils.random(16, true, true).toUpperCase();
            UserFileInfoQuery userFileInfoQuery = new UserFileInfoQuery();
            userFileInfoQuery.setId(random);
            UserFileInfo userFileInfo = get(userFileInfoQuery);
            if(userFileInfo == null){
                break;
            }
        }
        query.setId(random);
        Integer insert = userFileInfoMapper.insert(query);
        if(insert>0){
            return query;
        }else {
            return null;
        }
    }
    @Override
    public Integer insert(UserFileInfo query) {

       return userFileInfoMapper.insert(query);
    }


    @Override
    public Integer delete(UserFileInfoQuery query) {
        return userFileInfoMapper.delete(query);
    }

    @Override
    public Integer update(UserFileInfoQuery query) {
        return userFileInfoMapper.update(query);
    }

    @Override
    public UserFileInfo get(UserFileInfoQuery query) {
        return userFileInfoMapper.get(query);
    }

    @Override
    public List<UserFileInfo> list(UserFileInfoQuery query) {

        return userFileInfoMapper.list(query);
    }

    @Override
    public List<UserFileInfo> list() {
        return userFileInfoMapper.list();
    }



}
